package cl.parser.internal;

import java.util.ArrayList;
import java.util.List;

import cl.parser.IParseNode;
import cl.parser.external.IdentifierNode;
import cl.parser.external.SemicolonNode;

public class FunctionCallNode extends InternalNode implements IFat {

    @Override
    public String prettyPrint(String indent) {
        String res = "";
        
        for(IParseNode p : children) {
            res += p.prettyPrint(indent);
        }
        
        return res + ";";
    }
    
    @Override
    protected List<IParseNode> getAllowed(IParseNode last, List<IParseNode> soFar) {
        List<IParseNode> allowed = new ArrayList<IParseNode>();
        
        if(last == null) {
            allowed.add(new IdentifierNode());
        } else if(last instanceof IdentifierNode) {
            allowed.add(new ArgumentsNode());
        } else if(last instanceof ArgumentsNode) {
            allowed.add(new SemicolonNode());
        }
        
        return allowed;
    }

    @Override
    protected boolean isValid(IParseNode last, List<IParseNode> soFar) {
        return last instanceof SemicolonNode;
    }

    @Override
    public void loseWeight() {
        children.remove(children.size() - 1);
    }

}
